var app=getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
      indexs:0,
      top:0,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that=this;
        var parent_id=options.parent_id;
        if(parent_id!=undefined){
            this.setData({
                parent_id:parent_id
              })
              wx.setStorageSync('parent_id',parent_id);
        }else{
            parent_id = wx.getStorageSync('parent_id');
        
        }
        var open=wx.getStorageSync('open'); 
        wx.showShareMenu({
            menus: ['shareAppMessage', 'shareTimeline'],
            success(res) {
              console.log(res)
            },
            fail(e) {
              console.log(e)
            }
          })      
        that.setData({
            platform:app.globalData.platform,    
            open:open,
             width:app.globalData.windowWidth,
            height:app.globalData.windowHeight,
            statusBarHeight:app.globalData.statusBarHeight,
            navHeight:app.globalData.navHeight,
            marginTop:app.globalData.navTitleTop,
            domain:app.globalData.platUrl
          })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
      this.getIndex();
    },
   getIndex(){
    let that=this;
    var open=wx.getStorageSync('open');
    console.log(open);
    var auth=open.auth;     
      wx.request({
          url: app.globalData.platUrl+'manage/getDepart',
          data:{user_id:open.user_id,from:1},
          success:function(res){
            console.log(res);          
              var data=res.data;
              console.log(data)
                that.setData({
                  shareTitle:data.shareTitle,
                  shareLogo:data.shareLogo,
                  staff:data.staff,
                  list:data.list,
                  title:data.title
                 })
            
      
          }
        })
   },
   showStaff(e){
    console.log(e);
    var index=e.currentTarget.dataset.index;
    var nowIndex=this.data.indexs;
    if(nowIndex==0){
      this.setData({
        indexs:index
      });
    }else{
      if(nowIndex==index){
        this.setData({
          indexs:0
        }); 
      }else{
        this.setData({
          indexs:index
        }); 
      }
    }
    console.log('index=>'+index);
      this.getStaff(index);
   },
   getStaff(id){
    let that=this;
    var open=wx.getStorageSync('open');
    console.log(open);
      wx.request({
          url: app.globalData.platUrl+'manage/getStaff',
          data:{user_id:open.user_id,id:id,fomr:1},
          success:function(res){
            console.log(res);          
              var data=res.data;
              console.log(data)
                that.setData({
                         staffList:data.staffList,
                 
                 })
            
      
          }
        })
   },
   showStore(e){
    console.log(e);
    var index=e.currentTarget.dataset.index;
    var storeIndex=this.data.storeIndex;
    if(storeIndex==0){
      this.setData({
        storeIndex:index
      });
    }else{
      if(storeIndex==index){
        this.setData({
          storeIndex:0
        }); 
      }else{
        this.setData({
          storeIndex:index
        }); 
      }
    }
    console.log('index=>'+index);
      this.getStore(index);
   },
   getStore(id){
    let that=this;
    var open=wx.getStorageSync('open');
    console.log(open);
      wx.request({
          url: app.globalData.platUrl+'manage/getStore',
          data:{user_id:open.user_id,id:id,fomr:1},
          success:function(res){
            console.log(res);          
              var data=res.data;
              console.log(data)
                that.setData({
                         store:data.store,
                 
                 })
            
      
          }
        })
   },
   setTop(e){
      var index=e.currentTarget.dataset.index;
      var top=this.data.top;
      if(top==index){

      }else{

        this.setData({
          top:index
        })    
      }
   },
   goBack:function(){
    wx.navigateBack();
},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})